**********************************
******Table 1: Summary statistics: baseline by group
**********************************
global user "`c(username)'"
global dirdata "C:\Users\\$user\Dropbox\CCT BJP\data"
global dir1  "$dirdata\Final data"
global dir2  "$dirdata\Results\graphs"
cd "$dir2"

clear 
set more off
capture log close


use "$dir1\pooled_hh.dta", clear
g age=age_m if hhmale==0
replace age=age_p if hhmale==1
g spanish=spanish_m if hhmale==0
replace spanish=spanish_p if hhmale==1

g hourswe_m=w_hoursw_m
replace hourswe_m=. if hoursw_m==0
g hourswe_p=hoursw_p
replace hourswe_p=. if hoursw_p==0
g avg_hourswe_t=avg_hoursw_t
replace avg_hourswe_t=. if avg_hoursw_t==0
keep if year==2005 & min_schooling>=1 & min_schooling<9


************************************************
*********Column 1: full study sample
************************************************

***** Three panels;
**Panel A: Work Outcomes- Adults hh-level
count if folio!=.

tabstat nwork  hoursw_t nselfemp [w=factor], col(stats) stats(mean sd ) f(%10.2g)

**Panel B: Working outcomes -Adult females
tabstat work_m hoursw_m hourswe_m informal4_m [w=factor] , col(stats) stats(mean sd) f(%10.2g)
**Panel C: Working outcomes -Adult males
tabstat work_p hoursw_p hourswe_p informal4_p [w=factor], col(stats) stats(mean sd) f(%10.2g)

**Panel D: Working/schooling outcomes -children
preserve
use "$dir1\pooled_children.dta", clear

g hourswe=hoursw
replace hourswe=. if hoursw==0
keep if year==2005 & schooling>=1 & schooling<9

count if work!=.
tabstat   work hoursw hourswe enroll attend [w=factor] , col(stats) stats(mean sd) f(%10.2g)

restore
**Panel E: household Characteristics
count if folio!=.
tabstat urban age spanish schooling np nadults nchild5 poverty [w=factor] , col(stats) stats( mean sd ) f(%10.2g)





************************************************
*********Column 2: cohorts that entry early to the treatment group
************************************************

local subsample "min_schooling>=1 & min_schooling<6"
* Counting the number of observations
count if folio!=. & `subsample'

tabstat nwork  hoursw_t nselfemp [w=factor]  if `subsample', col(stats) stats(mean sd ) f(%10.2g)

**Panel B: Working outcomes -Adult females

tabstat work_m hoursw_m hourswe_m informal4_m  [w=factor]  if `subsample', col(stats) stats(mean sd) f(%10.2g)
**Panel C: Working outcomes -Adult males
tabstat work_p hoursw_p hourswe_p informal4_p   [w=factor]  if `subsample', col(stats) stats(mean sd) f(%10.2g)

**Panel D: Working/schooling outcomes -children
preserve
use "$dir1\pooled_children.dta", clear

g hourswe=hoursw
replace hourswe=. if hoursw==0
keep if year==2005 & schooling>=1 & schooling<5

* Counting the number of observations:
count if work!=.

tabstat   work hoursw hourswe enroll attend [w=factor] , col(stats) stats(mean sd) f(%10.2g)

restore
**Panel E: household Characteristics
count if folio!=.  & `subsample'
tabstat urban age spanish schooling np nadults nchild5 poverty [w=factor]  if `subsample' , col(stats) stats( mean sd ) f(%10.2g) 


************************************************
*********Column 3: cohorts of late entrance into the treatment group
************************************************
local subsample "min_schooling>=6 & min_schooling<9"

* Counting the number of observations
count if folio!=. & `subsample' 

tabstat nwork  hoursw_t nselfemp [w=factor] if `subsample' , col(stats) stats(mean sd ) f(%10.2g)

**Panel B: Working outcomes -Adult females

tabstat work_m hoursw_m hourswe_m informal4_m   [w=factor] if `subsample' , col(stats) stats(mean sd) f(%10.2g)
**Panel C: Working outcomes -Adult males
tabstat work_p hoursw_p hourswe_p informal4_p   [w=factor] if `subsample' , col(stats) stats(mean sd) f(%10.2g)

**Panel D: Working/schooling outcomes -children
preserve
use "$dir1\pooled_children.dta", clear

g hourswe=hoursw
replace hourswe=. if hoursw==0
keep if year==2005 & schooling>=6 & schooling<9

* Counting the number of observations:
count if work!=.
tabstat   work hoursw hourswe enroll attend [w=factor] , col(stats) stats(mean sd) f(%10.2g)
restore

**Panel E: household Characteristics

count if folio!=. & `subsample'
tabstat urban age spanish schooling np nadults nchild5 poverty [w=factor] if `subsample' , col(stats) stats( mean sd ) f(%10.2g)


*****************************************************
*********Column 4: Using all households in the survey
*****************************************************

use "$dir1\data_2005_full", clear
egen age_filter=total(age>=6 & age<18), by(folio year)
replace age_filter=1 if age_filter>0 & age_filter!=.
*Subsample HH 
sum age_filter   if rel_head==1
preserve

keep if rel_head==1 & age_filter==1 //save 1 obs per HH
** Number of observations:
count if folio!=""

global hh_adults "  hh_works hh_hours hh_self"
global hh_female "  hh_f_works hh_f_hours hh_f_hours_work hh_f_self"
global hh_male "  hh_m_works hh_m_hours hh_m_hours_work hh_m_self"
global hh_dem "urban age spanish schooling n_household n_adults n_0_5 poor "

tabstat $hh_adults  [w=f_weight], col(stats) stats(mean sd  ) f(%10.2g) //Panel A: Adults in HH
tabstat $hh_female  [w=f_weight], col(stats) stats(mean sd  ) f(%10.2g) //Panel B: Female (head or partner) in HH
tabstat $hh_male  [w=f_weight], col(stats) stats(mean sd  ) f(%10.2g) //Panel C: Male (head or partner) in HH
tabstat $hh_dem  [w=f_weight], col(stats) stats(mean sd  ) f(%10.2g) //Panel E: Demographic characteristics

restore
* Number of observations for this panel
count  if inrange(age,6,18) 
tabstat   works hours_week_w hours_week_w_ifwork enrolled attendance [w=f_weight] /*
*/ if inrange(age,6,18), col(stats) stats(   mean sd  ) f(%10.2g) //Panel D: Kids between 8 and 18 years old
